package com.theten52.demo.io.s1;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 开启服务监听线程,当收到连接请求后,开启新的线程进行处理
 *
 * @author wangjin
 * @date 2021/3/11
 */
public class ServerThread implements Runnable {

    @Override
    public void run() {
        try {
            ServerSocket serverSocket = new ServerSocket(Constant.PORT);
            while (true) {
                Socket socket = serverSocket.accept();
                new Thread(new ServerProcessThread(socket)).start();
                //开启新的线程进行连接请求的处理
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
